<template>
  <div class="gdap-header">
    <div class="gdap-logo">
      <router-link to="/">
        <img src="../../assets/slogo.png" alt="新疆高考志愿辅助填报系统" class="gdap-logo-img"/>
      </router-link>
      <div class="gdap-userInfo" v-if="isLogin">
        <div class="gdap-login">
          <el-dropdown trigger="click">
            <span class="el-dropdown-link" style="font-size:1.2em;color:#fff;cursor: pointer;">
              <strong>{{username}}</strong> <img src="./usercenter.png" style="vertical-align: middle;">&nbsp;用户中心<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown" style="text-align:center">
              <el-dropdown-item style="background-color:#ECF5FF"><img src="./vip.png"><p>可用推荐次数 {{recommendNum}}</p><p style="text-align:right">可用预测次数 {{editXYNum}}</p></el-dropdown-item>
              <router-link to="/profile" style=" text-decoration:none"><el-dropdown-item>个人信息</el-dropdown-item></router-link>
              <!-- <router-link to="/paymentrecord" style=" text-decoration:none"> --><a @click="toPayment()"><el-dropdown-item>支付购买</el-dropdown-item></a><!-- </router-link> -->
              <router-link to="/historyrecord" style=" text-decoration:none"><el-dropdown-item >推荐记录</el-dropdown-item></router-link>
              <router-link to="/estimaterecord" style=" text-decoration:none"><el-dropdown-item >预测记录</el-dropdown-item></router-link>
              <!-- <el-dropdown-item><router-link to="/helpcenter" style=" text-decoration:none">帮助中心</router-link></el-dropdown-item>              -->
              <a @click="handleLogout" style=" text-decoration:none"><el-dropdown-item icon="el-icon-error">退出登录</el-dropdown-item></a>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <!-- 密码验证 -->
        
      </div>
    </div>

    
  </div>
</template>
<script>
import api from '@/utils/api'
import {subAgentList} from '@/constants/constants'
export default {
  data() {
    return {
      reconfirmPassword: '',
      passVisible: false,
      isLogin: false,
      loginModalVisible: false,
      loginForm: {
        username: '',
        pass: ''
      },
      username: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')).username : '测试用户',
      recommendNum: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')).recommendNum : 0,
      editXYNum: localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user')).editXYNum : 0,
    }
  },
  mounted() {
    this.isLoginIn()
    const agentUrl = window.location.href
    const agentUrlStart = agentUrl.toString().indexOf('//') + 2
    const agentUrlEnd = agentUrl.toString().indexOf('.')
    const agentName = agentUrl.substring(agentUrlStart, agentUrlEnd)
    localStorage.setItem('agentName', agentName)
    console.log(subAgentList.indexOf(localStorage.getItem("agentName")) < 0, ' ---aaa')
  },
  methods: {
    confirmPass() {
      api({
        url: "/nceeSysMgr/rest/LoginUtil/login",
        method: "post",
        data: {
          username: JSON.parse(localStorage.getItem("user")).userId,
          password: this.reconfirmPassword
        }
      }).then(res => {
        console.log(res, '  reconfirm ')
        if (res.data.state === "success") {
          this.$router.push('/paymentrecord')
        } else {
          this.$message({
            message: '密码错误，请重新输入！',
            type: 'warning'
          })
          this.reconfirmPassword = ''
        }
      });
    },
    toPayment() {
      if (subAgentList.indexOf(localStorage.getItem("agentName")) < 0) {
        this.$router.push('/paymentrecord')
      } else {
        this.$store.dispatch('common/changeConfirm')
      }
    },
    isLoginIn() {
      if (localStorage.getItem('user')) {
        this.isLogin = !this.isLogin
      }
    },
    login() {
      this.loginModalVisible = true
    },
    
    handleLogout() {
      api({
        url: '/nceeSysMgr/rest/LoginUtil/logout',
        method: 'post'
      })
      .then(res => {
        console.log(res)
        if (res.data.status === '0') {
          localStorage.removeItem('user')
          // window.location.href('/')
          this.$router.push('/')
          window.location.reload()
          
        }
      })
    }
  }
}
</script>

<style>
  .gdap-header {
    width: 100%;
    height: 54px;
    background: #222222;
    z-index: 9998;
  }
  .gdap-logo{
    width: 100%;
    display: block;
    vertical-align: center;
    line-height: 54px;
  }
  .gdap-logo-img {
    margin-left: 10%;
    width: 15%;
    vertical-align: middle;
  }
  .gdap-userInfo {
    float: right;
    width: 40%;
    color: white;
    line-height: 54px;
  }
  .gdap-login {
    float: right;
    margin-right: 30%;
    line-height: 54px;
  }
  .gdap-login-action {
    margin-right: 10px;
  }
  .el-dropdown-menu{
    padding: 0px;
  }

</style>

